package cn.janescott.inner.space.shiro.realm;

import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.cache.CacheManager;
import org.apache.shiro.realm.AuthenticatingRealm;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.data.redis.core.StringRedisTemplate;

/**
 * @see AuthenticatingRealm#AuthenticatingRealm(CacheManager, CredentialsMatcher)
 * 默认情况下，cache是不使用的。
 * 对于使用redis作为数据源，暂时不需要使用本地cache
 * 基于redis的认证数据源
 * Created by Scott on 2018/7/27
 */
public class RedisPojoTokenRealm extends AuthorizingRealm {
    private StringRedisTemplate template;

    public RedisPojoTokenRealm(StringRedisTemplate template, Class<? extends AuthenticationToken> clazz) {
        super();
        this.template = template;
        setAuthenticationTokenClass(clazz);
    }

    public RedisPojoTokenRealm(StringRedisTemplate template, CredentialsMatcher matcher, Class<? extends AuthenticationToken> clazz) {
        super(matcher);
        this.template = template;
        setAuthenticationTokenClass(clazz);
    }

    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        return null;
    }

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        return null;
    }

    public StringRedisTemplate getTemplate() {
        return template;
    }

    public void setTemplate(StringRedisTemplate template) {
        this.template = template;
    }
}
